package util

import (
	"eat-every-day/pkg/logs"
	"time"
)

func UnixToString(timeStamp int) string {
	t := time.Unix(int64(timeStamp), 0)
	return t.Format("2006-01-02 15:04:05")
}

func GetTimeString(interval time.Duration) string {
	return time.Now().Add(interval * time.Minute).Format("2006-01-02 15:04:05")
}

func StringToUnix(str string) int64 {
	template := "2006-01-02 15:04:05"
	t, err := time.ParseInLocation(template, str, time.Local)
	if err != nil {
		logs.Log.Error("字符串转换成unix发生错误：", err)
		return 0
	}
	return t.Unix()
}
